import React from 'react';
import SID, { SID_STAND, SID_OPEN_IN_TYPE } from './SID';
// import SIDButtonView from './SIDButtonView.tsx';
import { SafeAreaView, ScrollView, StyleSheet, Button, View, useColorScheme } from 'react-native';
import { Colors } from 'react-native/Libraries/NewAppScreen';
// const SIDButton = SIDButtonView;

const App = () => {
  const isDarkMode = useColorScheme() === 'dark';

  const backgroundStyle = {
    backgroundColor: isDarkMode ? Colors.darker : Colors.lighter,
  };

  const onPressInitialize = () => {
    SID.initialize(
      "clientIdExample",
      "ExampleApp",
      "#ffffff",
      "#000000",
      "https://example.com",
      true,
      SID_STAND.PSI_STAND
    );
    console.log('SDK Initialized');
  };

  const onPressAuth = () => {
    SID.auth('scope', 'state', 'nonce', 'redirectUri');
  };

  const onPressLoginWithIDWeb = () => {
    SID.loginWithIDWeb(
      'scope',
      'state',
      'nonce',
      'redirectUri',
      'svcRedirectUrlString',
      undefined,
      undefined,
      undefined,
      undefined,
      (response) => {
        console.log("Результат операции:", response);
      });
  };

  const onPressAutoAuth = () => {
    SID.autoAuth(
      'scope',
      'state',
      'nonce',
      'redirectUri',
      'ssoBaseUrl',
      'codeChallenge',
      'codeChallengeMethod',
      'loginHint',
      (response) => {
        console.log("Результат операции:", response);
      });
  };

  const onPressSendOtherAuth = () => {
    SID.sendOtherAuth('AuthServiceName', true, true);
  };

  const onPressSetUserID = () => {
    SID.setUserID('userID');
  };

  const onPressSetClientID = () => {
    SID.setClientID('clientID');
  };

  const onPressUpdateAppToken = () => {
    SID.updateAppToken(
      'scope',
      'clientId',
      'state',
      'nonce',
      'redirectUri',
      'codeChallenge',
      'codeChallengeMethod',
    (error, result) => {
      if (error) {
        console.error('Error updating app token:', error);
      } else {
        console.log('App token updated successfully:', result);
      }
    },
    );
  };

  const onPressCheckAppTokenForValid = () => {
    SID.checkAppTokenForValid((error, result) => {
      if (error) {
        console.error('Error from check App Token response:', error);
      } else {
        console.log('Check App Token response:', result);
      }
    });
  };

  const handlePress = () => {
    console.log('Кнопка нажата');
  };

  return (
    <SafeAreaView style={[styles.container, backgroundStyle]}>
      <ScrollView contentInsetAdjustmentBehavior="automatic" style={backgroundStyle}>
        <View style={styles.buttonContainer}>
          <Button title="Initialize SDK" onPress={onPressInitialize} />
          <Button title="Auth" onPress={onPressAuth} />
          <Button title="Login With ID Web" onPress={onPressLoginWithIDWeb} />
          <Button title="Auto Auth" onPress={onPressAutoAuth} />
          <Button title="Send Other Auth" onPress={onPressSendOtherAuth} />
          <Button title="Set User ID" onPress={onPressSetUserID} />
          <Button title="Set Client ID" onPress={onPressSetClientID} />
          <Button title="Update App Token" onPress={onPressUpdateAppToken} />
          <Button title="Check App Token For Valid" onPress={onPressCheckAppTokenForValid} />
          <View style={styles.customButtonContainer}>
          </View>
        </View>
      </ScrollView>
    </SafeAreaView>
  );
};

const styles = StyleSheet.create({
  container: {
    flex: 1,
  },
  buttonContainer: {
    margin: 10,
  },
  customButtonContainer: {
    alignItems: 'center',
    justifyContent: 'center',
    flex: 1,
  },
});

export default App;
